package com.loongxun.playwithyou.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.loongxun.playwithyou.ApiInterface;
import com.loongxun.playwithyou.App;
import com.loongxun.playwithyou.R;
import com.loongxun.playwithyou.bean.Member;
import com.loongxun.playwithyou.bean.OrderMeg;
import com.loongxun.playwithyou.ui.activity.MemberListActivity;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

/**
 * Created by Administrator on 2017/8/25.
 */
public class ReportAdapter extends BaseAdapter {

    private Context context;
    public List<OrderMeg> list;
    private LayoutInflater inflater;
    private ImageLoader imageLoader = ImageLoader.getInstance();

    public ReportAdapter(Context context, List<OrderMeg> list){
        this.context = context;
        this.list = list;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        final ViewHolder holder;
        if(convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.item_report_list, null);

            holder.tv_item_list_user_name = (TextView) convertView.findViewById(R.id.tv_item_list_user_name);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        final OrderMeg item = list.get(position);

        holder.tv_item_list_user_name.setText(item.getOrder_no());
        if (item.getOrderState() == 1){
            holder.tv_item_list_user_name.setSelected(true);
        }else {
            holder.tv_item_list_user_name.setSelected(false);
        }

        holder.tv_item_list_user_name.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (item.getOrderState() == 1) {
                    item.setOrderState(0);
                }else {
                    item.setOrderState(1);
                }
                notifyDataSetChanged();
            }
        });

        return convertView;
    }

    class ViewHolder {
        private TextView tv_item_list_user_name;
    }

}
